/**
 *  This file is part of TaoBaoItemImporter.
 *
 *   TaoBaoItemImporter is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   TaoBaoItemImporter is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with TaoBaoItemImporter.  If not, see <http://www.gnu.org/licenses/>. 
 */
package com.googlecode.ulysses.taobao;

import java.util.HashMap;

/**
 * Define all the constants used by the project.
 * 
 * @author Ulysses <robman1070@gmail.com>
 * 
 */
public final class Constants {

	public static final String DEFAULT_EMPTY_STRING = "";
	public static final double DEFAULT_ZERO_DOUBLE = 0f;
	public final static int DEFAULT_ZERO_INT = 0;

	public final static String ADMIN_USER = "admin";
	public final static String NOT_AVAILABLE = "N/A";
	public final static double DEFAULT_ITEM_RATING = DEFAULT_ZERO_DOUBLE;
	public final static double DEFAULT_PRICE = DEFAULT_ZERO_DOUBLE;
	public final static double DEFAULT_CASH_BACK = DEFAULT_ZERO_DOUBLE;
	public final static int DEFAULT_NUM_RATING = DEFAULT_ZERO_INT;
	public final static int DEFAULT_ITEM_MAIN_CATS = DEFAULT_ZERO_INT;
	public final static int DEFAULT_ITEM_SUB_CATS = DEFAULT_ZERO_INT;
	public final static int DEFAULT_TIME_ZONE = 8;
	public final static boolean DEFAULT_IS_SOLD_OUT = false;
	public static final String DEFAULT_URL = DEFAULT_EMPTY_STRING;
	public static final String DEFAULT_WEBSITE = "http://www.taobao.com";
	public static final String DEFAULT_MERCHANT = DEFAULT_EMPTY_STRING;
	public static final String DEFAULT_DATE_FORMAT_PATTERN = "yyyy-MM-dd HH:mm:ss";
	public static final Object DEFAULT_EMPTY_DATE = "1970-01-00 00:00:00";
	public static final int DEFAULT_MONGO_PORT = 27017;
	public static final String DEFAULT_MONGO_HOST = "localhost";
	public static final double DEFAULT_RATING = DEFAULT_ZERO_DOUBLE;
	public static final String DEFAULT_USER_NAME = DEFAULT_EMPTY_STRING;
	public static final String PROPERTY_SEPARATOR = "  ";

	public static final String DEFAULT_OUTPUT_DIR = ""; //Current directory
	public final static String DEFAULT_API_URL = "http://gw.api.taobao.com/router/rest";
	public final static String DEFAULT_FIELDS = "click_url,num_iid,commission,commission_rate";
	
	public final static String DEFAULT_CATEGORY_NAME = "";
	public final static String DEFAULT_SUB_CATEGORY_NAME = "";
	
	public static final Object DEFAULT_ITEM_SOURCE = "Taobao";
	
	/**
	 * Each sub-category has its own property mapper 
	 * 
	 * TODO: Change to read the configuration from a file.
	 */
	public static class PropMap {
		private HashMap<String, String> bagMapper = new HashMap<String, String>();
		private HashMap<String, String> desktopMapper = new HashMap<String, String>();
		private HashMap<String, String> clothesMapper = new HashMap<String, String>();
		
		PropMap() {
			bagMapper.put("颜色分类", "color");
			// TODO Compete other mappers.
		}

		public final HashMap<String, String> getBagMapper() {
			return bagMapper;
		}

		public final HashMap<String, String> getDesktopMapper() {
			return desktopMapper;
		}

		public final HashMap<String, String> getClothesMapper() {
			return clothesMapper;
		}
		
	}
	public static final PropMap PROPERTY_MAP = new PropMap();

	public enum ItemType {
		/*
		 * Before adding a new type, ensure corresponding class has been created.
		 * 
		 * Add a new type both here and in method toItemType().
		 */
		ITEM_TYPE_UNKNOWN(0), ITEM_TYPE_DIGITAL(1), ITEM_TYPE_CLOTHES(2), ITEM_TYPE_BAG(3), ITEM_TYPE_BOOK(5);

		private int num = 0;

		private ItemType(int num) {
			this.num = num;
		}
		
		public int getItemTypeNumber(){
			return this.num;
		}

		public ItemType toItemType(String num) {
			return toItemType(Integer.parseInt(num));
		}
		
		public ItemType toItemType(int num) {
			switch (num) {
			case 1:
				return ITEM_TYPE_DIGITAL;
			case 2:
				return ITEM_TYPE_CLOTHES;
			case 3:
				return ITEM_TYPE_BAG;
			case 5:
				return ITEM_TYPE_BOOK;
			default:
				return ITEM_TYPE_UNKNOWN;
			}
		}
	}
	
	public static final PropertyMapping PROP_MAPPING = new PropertyMapping();

	public static ItemType ITEM_TYPES = ItemType.ITEM_TYPE_UNKNOWN;
}
